package org.jeecg.modules.demo.zhengchai.fundallocation.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.zhengchai.fundallocation.entity.FundAllocation;
import org.jeecg.modules.demo.zhengchai.fundallocation.service.FundAllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fund-allocation")
public class FundAllocationController {

    @Autowired
    private FundAllocationService fundAllocationService;

    /**
     * 获取资金分配列表
     * @param page 分页对象
     * @param fundAllocation 查询条件
     * @return 分页结果
     */
    @GetMapping("/list")
    public Page<FundAllocation> list(Page<FundAllocation> page, FundAllocation fundAllocation) {
        QueryWrapper<FundAllocation> queryWrapper = new QueryWrapper<>(fundAllocation);
        return fundAllocationService.page(page, queryWrapper);
    }

    /**
     * 添加资金分配
     * @param fundAllocation 资金分配对象
     * @return 是否添加成功
     */
    @PostMapping("/add")
    public boolean add(@RequestBody FundAllocation fundAllocation) {
        return fundAllocationService.save(fundAllocation);
    }

    /**
     * 修改资金分配
     * @param fundAllocation 资金分配对象
     * @return 是否修改成功
     */
    @PutMapping("/edit")
    public boolean edit(@RequestBody FundAllocation fundAllocation) {
        return fundAllocationService.updateById(fundAllocation);
    }

    /**
     * 删除资金分配
     * @param id 资金分配ID
     * @return 是否删除成功
     */
    @DeleteMapping("/delete")
    public boolean delete(@RequestParam("id") Long id) {
        return fundAllocationService.removeById(id);
    }

    /**
     * 根据ID查询资金分配
     * @param id 资金分配ID
     * @return 资金分配对象
     */
    @GetMapping("/queryById")
    public FundAllocation queryById(@RequestParam("id") Long id) {
        return fundAllocationService.getById(id);
    }
}
